<template>
	<view>
		<view>
			<uni-nav-bar shadow left-icon="left" dark title="采购单审核详细" @clickLeft="back()" />
		</view>
		<view>
			
			<uni-card>
				
				<uni-table border stripe>
					<uni-tr style="white-space: nowrap">
					    <uni-th align="center" colspan="8">物料信息</uni-th>
						<uni-th align="center" colspan="4" style="background-color: burlywood;">供应商一</uni-th>
						<uni-th align="center" colspan="4" style="background-color:chartreuse">供应商二</uni-th>
						<uni-th align="center" colspan="4" style="background-color:blueviolet">供应商三</uni-th>
					</uni-tr>
					<uni-tr style="white-space: nowrap">
					    <uni-th align="center">申请单ID</uni-th>
						<uni-th align="center">物料编码</uni-th>
						<uni-th align="center">物料描述</uni-th>
						<uni-th align="center">规格型号</uni-th>
						<uni-th align="center">采购数量</uni-th>
						<uni-th align="center">比价数量</uni-th>
						<uni-th align="center"style="background-color:chartreuse">平台单价</uni-th>
						<uni-th align="center"style="background-color:chartreuse">平台金额</uni-th>
						<uni-th align="center" style="background-color: burlywood;">选择</uni-th>
						<uni-th align="center"style="background-color: burlywood;">单价</uni-th>
						<uni-th align="center"style="background-color: burlywood;">总价</uni-th>
						<uni-th align="center"style="background-color: burlywood;">交期</uni-th>
						<uni-th align="center"style="background-color:chartreuse">选择</uni-th>

						<uni-th align="center"style="background-color:chartreuse">单价</uni-th>
						<uni-th align="center"style="background-color:chartreuse">总价</uni-th>
						<uni-th align="center"style="background-color:chartreuse">交期</uni-th>
						<uni-th align="center"style="background-color:blueviolet">选择</uni-th>
						<uni-th align="center"style="background-color:blueviolet">单价</uni-th>
						<uni-th align="center"style="background-color:blueviolet">总价</uni-th>
						<uni-th align="center"style="background-color:blueviolet">交期</uni-th>
						
					</uni-tr>
					<uni-tr v-for="(item,index) in inquirycheckItem" :key="index" style="white-space: nowrap">
					    
						 <uni-td align="center">{{item.applyId}}</uni-td>
						 <uni-td align="center">{{item.itemCode}}</uni-td>
						 <uni-td align="center">{{item.itemDesc}}</uni-td>
						 <uni-td align="center">{{item.specification}}</uni-td>
						<uni-td align="center">{{item.itemQuantity}}</uni-td>
						<uni-td align="center">{{item.itemCompareQuantity}}</uni-td
						 <uni-td align="center">{{item.itemQuantity}}</uni-td>
						 <uni-td align="center">{{item.itemCompareQuantity}}</uni-td
						 
						 <uni-td align="center" style="background-color: burlywood;"><uni-data-checkbox  v-model="applyId['apply'+item.applyId]" :localdata="sex1"  @change="change(applyId)" ></uni-data-checkbox></uni-td>
						 <uni-td align="center" style="background-color: burlywood;">{{item.price1}}</uni-td>
					     <uni-td align="center" style="background-color: burlywood;">{{item.totalMoney1}}</uni-td>
					     <uni-td align="center" style="background-color: burlywood;">{{item.transitDate1}}</uni-td>
						 <uni-td align="center"style="background-color:chartreuse"><uni-data-checkbox   v-model="applyId['apply'+item.applyId]" :localdata="sex2"           @change="change(applyId)" ></uni-data-checkbox></uni-td>
						 <uni-td align="center"style="background-color:chartreuse">{{item.price2}}</uni-td>
						 <uni-td align="center"style="background-color:chartreuse">{{item.totalMoney2}}</uni-td>
						 <uni-td align="center"style="background-color:chartreuse">{{item.transitDate2}}</uni-td>
						 <uni-td align="center"style="background-color:blueviolet;color: #fff;"><uni-data-checkbox v-model="applyId['apply'+item.applyId]" :localdata="sex3"  @change="change(applyId)"></uni-data-checkbox></uni-td>
						 <uni-td align="center"style="background-color:blueviolet;color: #fff;">{{item.price3}}</uni-td>
						 <uni-td align="center"style="background-color:blueviolet;color: #fff;">{{item.totalMoney3}}</uni-td>
						 <uni-td align="center"style="background-color:blueviolet;color: #fff;">{{item.transitDate3}}</uni-td>
					</uni-tr>	
				</uni-table>	
				
				<uni-row><text style="font-weight: 600;">审批意见:</text><uni-easyinput type="textarea" v-model="optDesc"></uni-easyinput></uni-row>

				<uni-row style="margin-top: 20rpx;">
					<uni-col :span="12" style="text-align: center;"><button size="mini" type="primary" @click="add()">通过</button></uni-col>
					<uni-col :span="12" style="text-align: center;"><button size="mini" type="warn" @click="endgoBack()">驳回</button></uni-col>
				</uni-row>
				
			<view style="margin-top: 15rpx;">
				<uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#ffaa00" @clickItem="onClickItem" style="background-color: #fff"  />
			</view>
			<view>
				<view v-if="current === 0">
				<uni-table border stripe >
						<uni-tr style="white-space: nowrap">
							<uni-th align="center">序号</uni-th>
							<uni-th align="center">状态</uni-th>
							<uni-th align="center">流程</uni-th>
							<uni-th align="center">审批人</uni-th>
							<uni-th align="center">推荐供应商</uni-th>
							<uni-th align="center">审批意见</uni-th>
							<uni-th align="center">结果</uni-th>
							<uni-th align="center">审批日期</uni-th>
						</uni-tr>
						<uni-tr v-for="(items,indexs) in inquirycheckOrderId" :key="indexs" style="white-space: nowrap">
							<uni-td align="center">{{items.seqNum}}</uni-td>
							<uni-td align="center">{{items.statusName}}</uni-td>
							<uni-td align="center">{{items.flowName}}</uni-td>
							<uni-td align="center">{{items.optName}}</uni-td>
							<uni-td align="center">{{items.recommend}}</uni-td>
							<uni-td align="center">{{items.optDesc}}</uni-td>
							<uni-td align="center">{{items.optResult}}</uni-td>
							<uni-td align="center">{{items.createdDate}}</uni-td>
						</uni-tr>
				
					</uni-table>
				</view>
						
				<view v-if="current === 1">
					<uni-table border stripe >
							<uni-tr style="white-space: nowrap">
								<uni-th align="center">创建日期</uni-th>
								<uni-th align="center">比价单号</uni-th>
								<uni-th align="center">物料总数</uni-th>
								<uni-th align="center">供应商1</uni-th>
								<uni-th align="center">总报价1</uni-th>
								<uni-th align="center">交期1</uni-th>
								<uni-th align="center">供应商2</uni-th>
								<uni-th align="center">总报价2</uni-th>
								<uni-th align="center">交期2</uni-th>
								<uni-th align="center">供应商3</uni-th>
								<uni-th align="center">总报价3</uni-th>
								<uni-th align="center">交期3</uni-th>
							</uni-tr>
							<uni-tr v-for="(item,index) in inquirycheckSourceId" :key="index" style="white-space: nowrap">
								<uni-td align="center">{{item.createdDate}}</uni-td>
								<uni-td align="center">{{item.compareNum}}</uni-td>
								<uni-td align="center">{{item.itemQuantity}}</uni-td>
								<uni-td align="center">{{item.supplierName1}}</uni-td>
								<uni-td align="center">{{item.totalMoney1}}</uni-td>
								<uni-td align="center">{{item.transitDate1}}</uni-td>
							    <uni-td align="center">{{item.supplierName2}}</uni-td>
							    <uni-td align="center">{{item.totalMoney2}}</uni-td>
							    <uni-td align="center">{{item.transitDate2}}</uni-td>
							    <uni-td align="center">{{item.supplierName3}}</uni-td>
							    <uni-td align="center">{{item.totalMoney3}}</uni-td>
							    <uni-td align="center">{{item.transitDate3}}</uni-td>
							</uni-tr>
					
						</uni-table>
				</view>	
						
				<view v-if="current === 2">
				<uni-table border stripe >
						<uni-tr style="white-space: nowrap">
							<uni-th align="center">比价单号</uni-th>
							<uni-th align="center">物料编码</uni-th>
							<uni-th align="center">物料名称</uni-th>
							<uni-th align="center">规格型号</uni-th>
							<uni-th align="center">比价数量</uni-th>
							<uni-th align="center">供应商一</uni-th>
							<uni-th align="center">报价一</uni-th>
							<uni-th align="center">供应商二</uni-th>
							<uni-th align="center">报价二</uni-th>
							<uni-th align="center">供应商三</uni-th>
							<uni-th align="center">报价三</uni-th>
							
						</uni-tr>
						<uni-tr v-for="(itemcheck,indexcheck) in inquirycheckItem" :key="indexcheck" style="white-space: nowrap">
							<uni-td align="center">{{itemcheck.compareNum}}</uni-td>
							<uni-td align="center">{{itemcheck.itemDesc}}</uni-td>
							<uni-td align="center">{{itemcheck.itemQuantity}}</uni-td>
							<uni-td align="center">{{itemcheck.specification}}</uni-td>
							<uni-td align="center">{{itemcheck.itemCompareQuantity}}</uni-td>
							<uni-td align="center">{{itemcheck.supplierName1}}</uni-td>
						    <uni-td align="center">{{itemcheck.totalMoney1}}</uni-td>
						    <uni-td align="center">{{itemcheck.supplierName2}}</uni-td>
						    <uni-td align="center">{{itemcheck.totalMoney2}}</uni-td>
						    <uni-td align="center">{{itemcheck.supplierName3}}</uni-td>
						    <uni-td align="center">{{itemcheck.totalMoney3}}</uni-td>
						    
						</uni-tr>
				
					</uni-table>
				</view>	
				
			</view>		
			</uni-card>
		</view>
		
	</view>
</template>

<script>
	import {goBackSaveForm,editSaveForm,editUIAPPWorkCheckOrderForm,WorkCheckFlowFormDatatable,OrderCompareFormSourceId,OrderCompareDatatableItem} from "@/api/system/user"
	export default {
		data() {
			return {
				applyId:{},
			  rowId:null,
				sex1: [{
					value: '1'
						}],
						
				sex2: [{	
					value: '2'
					}],
				sex3: [{
					value: '3'
					}],					
			current:0,
			optDesc:null,
			inquirycheckSourceId:null,
			inquirycheckOrderId:null,
			inquirycheckItem:null,
			items: ['审批流程', '采购比价单','采购明细'],		
			}
		},
		onLoad() {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', (data) => {
				this.from = data.data
				})
			this.get()
			
		},
		
		methods: {
		    endgoBack(){
				if(this.optDesc==null||this.optDesc==''){
					alert("请填写审核意见")
					return
				}
				goBackSaveForm(this.rowId,this.optDesc).then(res=>{
					this.$tab.reLaunch('/pages/work/purchaser/inquiry_review')
				})
			},
			change(e){
				// console.log(JSON.stringify(this.applyId))
				// this.applyId
			},
			 add(){
				 if(this.optDesc==null||this.optDesc==''){
				 	alert("请填写审核意见")
				 	return
				 }
				let rowId=this.rowId
				let  data={
					rowId:rowId,
					optName:this.optName,
				    optDesc:this.optDesc
				}
	            let person = {...data, ...this.applyId};  
				 editSaveForm(person).then(res=>{
				 	this.$tab.reLaunch('/pages/work/purchaser/inquiry_review')
				 })
			 },
			 
			get(){
				
				editUIAPPWorkCheckOrderForm(this.from.rowId).then(res=>{
					if(res.flag){
						//查询审批单
						WorkCheckFlowFormDatatable(this.from.rowId).then(res=>{
							this.inquirycheckOrderId=res.rows
						})
						//查询比价单
						OrderCompareFormSourceId(this.from.sourceId).then(res=>{
							this.inquirycheckSourceId=res.rows
						})
						//查询采购明细
						OrderCompareDatatableItem(this.from.sourceId).then(res=>{
							this.inquirycheckItem=res.rows
						})
					}else{
						this.$tab.reLaunch('/errer/failed')
					}
					
					this.rowId=res.data.form.rowId
					// alert(this.rowId)
				})
				
				
				
			},
			back(){
					this.$tab.reLaunch('/pages/work/purchaser/inquiry_review')
			},
			onClickItem(e) {
						if (this.current !== e.currentIndex) {
							this.current = e.currentIndex
						}
					},
		}
	}
</script>

<style>

</style>
